//
//  MainTableHeaderView.m
//  MainNavSearchAndSegmentDemo
//
//  Created by dihuijun on 17/5/26.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "MainTableHeaderView.h"

@interface MainTableHeaderView ()<SDCycleScrollViewDelegate>




@end



@implementation MainTableHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
#pragma mark --- 1.setup
- (void)setup{
    NSArray *imagesURLStrings = @[
                                  @"https://ss2.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a4b3d7085dee3d6d2293d48b252b5910/0e2442a7d933c89524cd5cd4d51373f0830200ea.jpg",
                                  @"https://ss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=a41eb338dd33c895a62bcb3bb72e47c2/5fdf8db1cb134954a2192ccb524e9258d1094a1e.jpg",
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"
                                  ];
    NSArray *titles = @[@"介绍1",
                        @"介绍2",
                        @"介绍3",
                        @"介绍4"
                        ];
    
    
    
    //1.宽度
    CGFloat w = self.bounds.size.width;
    //网络加载  －－－－ 创建带标题的图片轮播器
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, 180) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    self.cycleScrollView.titlesGroup = titles;
    // 自定义分页控件小圆标颜色
    self.cycleScrollView.currentPageDotColor = [UIColor whiteColor];
    [self addSubview:self.cycleScrollView];
    //模拟加载延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
    });
    
    
    
//    self.backgroundColor = [UIColor orangeColor];
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    //NSLog(@"---点击了第%ld张图片", (long)index);
    
    !self.tapblock ?: self.tapblock(index);
    
}


@end
